/**
 * Map Navigator Class
 * A class used to track position and movement
 * through a 2 dimensional matrix
 */
function mapNavigator()
{
	var _this = this,
	_map = null,
	_currentPos = {
		x: 0,
		y: 0
	};
	/**
	 * Set Matrix of map items
	 * @param {Array} map
	 */
	function _setMap( map )
	{
		if ( !(map instanceof Array))
		{
			throw new Error('map must be an Array');
		}
		_map = map;
	}
	/**
	 * Return Matrix of map items
	 * @return {Array} map
	 */
	function _getMap( map )
	{
		return _map;
	}
	/**
	 * Return the current position within the map matrix
	 * @param {Object} position
	 */	
	function _getCurrentMapPosition(  )
	{
		return _currentPos;
	}
	
	function _getCurrentMapItem( )
	{
		try
		{
			var item = _map[_currentPos.x][_currentPos.y];
			return item;
		} catch (e) {
			console.dir(e);
			return false;
		}
	}
	
	function _updateXPosition( x )
	{
		var oldX = _currentPos.x;
		_currentPos.x = x;
		if ( _isAtMaxX() )
		{
			_currentPos.x = oldX;
			return false;
		}
		return true;
	}
	
	function _updateYPosition( y )
	{
		var oldY = _currentPos.y;
		_currentPos.y = y;
		if ( _isAtMaxY() )
		{
			_currentPos.y = oldY;
			return false;
		}
		return true;
	}
	
	function _isAtMaxX()
	{
		if ( _currentPos.x < _map.length )
		{
			return false;
		}
		return true;
	}
	
	function _isAtMaxY()
	{
		if ( _currentPos.y < _map[_currentPos.x].length )
		{
			return false;
		}
		return true;
	}
	
	
	/** Public Interfaces **/
	this.getMap = _getMap;
	this.setMap = _setMap;
	this.getCurrentMapPosition = _getCurrentMapPosition;
	this.getCurrentMapItem = _getCurrentMapItem;
	this.updateXPosition = _updateXPosition;
	this.updateYPosition = _updateYPosition;
}
